module ProductsHelper
  def show_categories(categories, length = nil)
    categories = categories.map(&:name).sort{ |a,b| a <=> b }.join(', ')

    unless length.blank?
      categories = truncate(categories, :length => length)
    end

    categories
  end

  def get_product(product_id)
    @product = Product.find(product_id)
  end

  def get_color_name(color_id)
    unless color_id.blank?
      ProductColor.find(color_id).color_name
    else
      'Unico'
    end
  end

  def show_subtotal(price, quantity)
    number_to_currency(price * quantity)
  end
end
